package main

import (
	"fmt"
	"myetcd_demo/client"
	"time"
)

func main() {
	endpoints := []string{"localhost:2379"}
	tsClient, err := client.NewEtcdDiscover(endpoints)
	if err != nil {
		fmt.Println("new etcdDiscover failure,err:", err)
		return
	}
	err = tsClient.GetValueByPrefix("/phpServer")
	if err != nil {
		fmt.Println("get value failure,err:", err)
		return
	}
	go tsClient.WatchPrefix("/phpServer")
	//test
	go func() {
		for {
			tsClient.ServerList.Range(func(k, v interface{}) bool {
				fmt.Printf("key = %s value= %s\n", k, v)
				return true
			})
			time.Sleep(5 * time.Second)
		}
	}()
	time.Sleep(500 * time.Second)
}
